/* PR c/102989 */
/* { dg-do run { target { bitint && int32plus } } } */
/* { dg-options "-std=gnu23" } */
/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */

#ifdef __SIZEOF_INT128__
#define int128_val(x, y) x
#define int128 __int128
#else
#define int128_val(x, y) y
#define int128 int
#endif

#if __BITINT_MAXWIDTH__ >= 575
__attribute__((noipa)) void
test575 (_BitInt(575) *a, int b, int128 c, unsigned int d, unsigned int128 e,
	 int f, int g, int128 h, unsigned int i, unsigned int128 j,
	 _BitInt(575) *p, int *r)
{
  r[0] = *a > b;
  r[1] = *a >= c;
  r[2] = *a < d;
  r[3] = *a <= e;
  p[0] = ((_BitInt(575)) g) << f;
  p[1] = ((_BitInt(575)) h) << f;
  p[2] = ((_BitInt(575)) i) << f;
  p[3] = ((_BitInt(575)) j) << f;
  p[4] = ((unsigned _BitInt(575)) g) >> f;
  p[5] = ((unsigned _BitInt(575)) h) >> f;
  p[6] = ((unsigned _BitInt(575)) i) >> f;
  p[7] = ((unsigned _BitInt(575)) j) >> f;
}

_BitInt(575) a575 = -37335077053906536248085160049937130279057714970866686325204063930452920311842187828021093674979068589644104434897698233644810906211958229904753029173357201859433853689386323wb;
#endif

int
main ()
{
#if __BITINT_MAXWIDTH__ >= 575
  int r[12];
  _BitInt(575) b575[24];
  int er[12] = {
#ifdef __SIZEOF_INT128__
    0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1
#else
    0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1
#endif
  };
  static _BitInt(575) eb575[24] = {
#ifdef __SIZEOF_INT128__
    20329374714419634196895318109902140892207297977139593216wb,
    -1712803473999893185713719997722323414959591613021414111612885795955340439235139207168wb,
    24459948786509903061037979887398299261116601758241521664wb,
    266261172647138617905132542512773540174694514212873439044818615992883558384930914304wb,
    0wb,
    10830740992659433045228180406808920716548582325686783496759685861775864483615725089999900023844295226942934417817982702456930303wb,
    0wb,
    0wb,
    7830590302633896968192wb,
    -659747899885375730707839505890120862245951494946816wb,
    9421629561223530938368wb,
    102560073085756776493593811652595116491535756034048wb,
    0wb,
    28118211215894977392565865673037386617935606989386978956879722328823984879196799189494004288149317857187005691459505594520051662846839338948136222520490158359458wb,
    0wb,
    5302231504909973601023497wb,
    1780470098wb,
    -150009304862891379049833518795394607479wb,
    2142230542wb,
    23319460771235020841594135084186545212wb,
    1780470098wb,
    -150009304862891379049833518795394607479wb,
    2142230542wb,
    23319460771235020841594135084186545212wb
#else
    20329374714419634196895318109902140892207297977139593216wb,
    479555224749202520035584085735030365824602865664wb,
    24459948786509903061037979887398299261116601758241521664wb,
    171269723124715185726994316333939416365929594880wb,
    0wb,
    0wb,
    0wb,
    0wb,
    7830590302633896968192wb,
    184717953466368wb,
    9421629561223530938368wb,
    65970697666560wb,
    0wb,
    0wb,
    0wb,
    0wb,
    1780470098wb,
    42wb,
    2142230542wb,
    15wb,
    1780470098wb,
    42wb,
    2142230542wb,
    15wb
#endif
  };
  test575 (&a575, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42),
	   2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15),
	   153, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42),
	   2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15),
	   &b575[0], &r[0]);
  a575 = 1780470099wb;
  test575 (&a575, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42),
	   2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15),
	   42, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42),
	   2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15),
	   &b575[8], &r[4]);
  a575 = -150009304862891379049833518795394607478wb;
  test575 (&a575, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42),
	   2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15),
	   0, 1780470098, int128_val (-150009304862891379049833518795394607479wb, 42),
	   2142230542U, int128_val (23319460771235020841594135084186545212uwb, 15),
	   &b575[16], &r[8]);
  for (int i = 0; i < 12; ++i)
    if (r[i] != er[i])
      __builtin_abort ();
  for (int i = 0; i < 24; ++i)
    if (b575[i] != eb575[i])
      __builtin_abort ();
#endif
}
